# 回合制对战游戏
# 创建角色：名字，性别，血量
# 战斗
# 创建房间
# 角色可以加入房间  房间的人可以互打  房间上限2人  装备防弹衣  血量默认100  正常被攻击-10滴血  有防弹衣5
import random


class Player:
    # 初始化人物数据
    def __init__(self, name, equipment):
        self.name = name
        self.hp = 100
        self.speed = 5
        self.despeed = 0
        self.defend = 0
        self.attack = 0
        self.eq_hp = 0
        self.equipment = equipment


equi_list = {'1': 'p1911', '2': '砍刀', '3': '安倍快乐枪', '4': '防弹衣'}


class Equipment(Player):
    def __init__(self, name, equipment):

        super().__init__(name, equipment)

    def p1911(self, bingo):
        # 手枪，初始攻击力10，速度10，暴击伤害1.5倍，80命中率，15暴击率
        attack_base = 10
        self.speed += 10
        if 0 <= bingo < 20:
            self.attack = 0
        elif 20 <= bingo < 85:
            self.attack = attack_base
        else:
            self.attack = attack_base * 1.5

    def kandao(self, bingo):
        # 砍刀，初始攻击力8，速度5，暴击伤害2倍，必中，30暴击率
        attack_base = 8
        self.speed += 5
        if 0 <= bingo <= 70:
            self.attack = attack_base
        else:
            self.attack = attack_base * 2

    def anbei_happy_gun(self, bingo):
        # 安倍快乐枪，初始攻击3/弹丸，最大10弹丸，速度2，无暴击，命中率折算90
        attack_base = 3
        self.speed += 2
        bingo_num = bingo // 10
        self.attack = attack_base * bingo_num

    def fangdanyi(self):
        self.eq_hp = 35
        self.defend = 5
        self.despeed = -6

    def fight(self, atk):
        bingo = random.randint(0, 100)
        self.speed = self.despeed
        atk = int(atk) - 1
        hit = self.equipment[atk]
        while True:
            if hit == '1':
                self.p1911(bingo)
                break
            elif hit == '2':
                self.kandao(bingo)
                break
            elif hit == '3':
                self.anbei_happy_gun(bingo)
                break
            elif hit == '4':
                self.fangdanyi()
                print("已装备防弹衣")
                self.equipment[atk] = '5'
                equi_list['5'] = '防弹衣(已装备)'
                break
            elif hit == '5':
                if atk == 0:
                    self.fight(2)
                else:
                    self.fight(1)
                print('你已经装备了防弹衣,自动为你选择了主武器')
                break
            else:
                print('请按要求输入')
                break


def roundfight():
    Round = 1
    while True:
        if player1.hp > 0 and player2.hp > 0:
            print('-' * 10, f'<Round{Round}>', '-' * 10)
            print(f'【{player1.name}的战术】\n当前血量{player1.hp}\n当前护甲{player1.eq_hp}')
            print(f'对方血量{player2.hp}\n对方护甲{player2.eq_hp}')
            print('#' * 30)
            atk1 = input(f'1:{equi_list[player1.equipment[0]]}\n2:{equi_list[player1.equipment[1]]}\n请选择你要使用的武器：')
            player1.fight(atk1)
            print('#' * 30)
            print(f'【{player2.name}的战术】\n当前血量{player2.hp}\n当前护甲{player2.eq_hp}')
            print(f'对方血量{player1.hp}\n对方护甲{player1.eq_hp}')
            print('#' * 30)
            atk2 = input(f'1:{equi_list[player2.equipment[0]]}\n2:{equi_list[player2.equipment[1]]}\n请选择你要使用的武器：')
            player2.fight(atk2)
        p1_hit = player1.attack - player2.defend
        if p1_hit < 0:
            p1_hit = 0
        p2_hit = player2.attack - player1.defend
        if p2_hit < 0:
            p2_hit = 0

        if player1.speed > player2.speed:
            if player1.hp > 0:
                player2.eq_hp = player2.eq_hp - player1.attack
                player2.hp = player2.hp - p1_hit
                if player2.hp > 0:
                    player1.eq_hp = player1.eq_hp - player2.attack
                    player1.hp = player1.hp - p2_hit
                else:
                    print(f'/////游戏结束，{player1.name}获胜！/////')
                    print(f'总回合数：{Round}\n使用武器：{equi_list[player1.equipment[0]]},{equi_list[player1.equipment[1]]}')
                    print(f'剩余血量：{player1.hp}')
                    print('#' * 30)
                    break
            else:
                print(f'/////游戏结束，{player2.name}获胜！/////')
                print(f'总回合数：{Round}\n使用武器：{equi_list[player2.equipment[0]]},{equi_list[player2.equipment[1]]}')
                print(f'剩余血量：{player2.hp}')
                print('#' * 30)
                break
            Round += 1
        elif player1.speed < player2.speed:
            if player2.hp > 0:
                player1.eq_hp = player1.eq_hp - player2.attack
                player1.hp = player1.hp - p2_hit
                if player1.hp > 0:
                    player2.eq_hp = player2.eq_hp - player1.attack
                    player2.hp = player2.hp - p1_hit
                else:
                    print(f'/////游戏结束，{player2.name}获胜！/////')
                    print(f'总回合数：{Round}\n使用武器：{equi_list[player2.equipment[0]]},{equi_list[player2.equipment[1]]}')
                    print(f'剩余血量：{player2.hp}')
                    print('#' * 30)
                    break
            else:
                print(f'/////游戏结束，{player1.name}获胜！/////')
                print(f'总回合数：{Round}\n使用武器：{equi_list[player1.equipment[0]]},{equi_list[player1.equipment[1]]}')
                print(f'剩余血量：{player1.hp}')
                print('#' * 30)
                break
            Round += 1
        else:
            if player1.hp > 0 and player2.hp > 0:
                player1.eq_hp = player1.eq_hp - player2.attack
                player1.hp = player1.hp - p2_hit
                player2.eq_hp = player2.eq_hp - player1.attack
                player2.hp = player2.hp - p1_hit
            elif player2.hp < 0 and player1.hp < 0:
                print('/////二人幸终/////')
                print('#' * 30)
                break
            else:
                if player1.hp > player2.hp:
                    print(f'/////游戏结束，{player1.name}获胜！/////')
                    print(f'总回合数：{Round}\n使用武器：{equi_list[player1.equipment[0]]},{equi_list[player1.equipment[1]]}')
                    print(f'剩余血量：{player1.hp}')
                    print('#' * 30)
                    break
                else:
                    print(f'/////游戏结束，{player2.name}获胜！/////')
                    print(f'总回合数：{Round}\n使用武器：{equi_list[player2.equipment[0]]},{equi_list[player2.equipment[1]]}')
                    print(f'剩余血量：{player2.hp}')
                    print('#' * 30)
                    break
            Round += 1
        if player1.eq_hp <= 0:
            player1.eq_hp = 0
            player1.defend = 0
        if player2.eq_hp <= 0:
            player2.eq_hp = 0
            player2.defend = 0
        print('#' * 30)
        print(f'{player1.name}使用了{equi_list[player1.equipment[(int(atk1) - 1)]]}造成了{p1_hit}点伤害')
        print(f'{player2.name}使用了{equi_list[player2.equipment[(int(atk2) - 1)]]}造成了{p2_hit}点伤害')
        print('#' * 30)


def equi_choose():
    for i in equi_list:
        print(f'{i}:{equi_list[i]}')


if __name__ == '__main__':
    p1_equipment = []
    p2_equipment = []
    player1 = input("please name player1:")
    print('#' * 30)
    equi_choose()
    print('#' * 30)
    e1 = input(f"请挑选{player1}的装备1:")
    p1_equipment.append(e1)
    e2 = input(f"请挑选{player1}的装备2:")
    p1_equipment.append(e2)
    player1 = Equipment(player1, p1_equipment)
    player2 = input("please name player2:")
    print('#' * 30)
    equi_choose()
    print('#' * 30)
    e1 = input(f"请挑选{player2}的装备1:")
    p2_equipment.append(e1)
    e2 = input(f"请挑选{player2}的装备2:")
    p2_equipment.append(e2)
    player2 = Equipment(player2, p2_equipment)
    roundfight()
